<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* proxy 数据代理 */
        let obj = {
            name:'yaoshang'
        }
        // proxy实例对象代理 传入的obj
        let proxy = new Proxy(obj,{
            get(target,key,receiver){
                // 目标对象
                console.log(target);
                // 属性名
                console.log(key);
                // proxy实例
                console.log(receiver);
                // get方法的返回值  不写返回值 undefined
                return target[key]
            },
            set(target,key,value,receiver){
                //  目标对象
                console.log(target);
                // 属性名
                console.log(key);
                // 属性值
                console.log(value);
                // proxy实例
                console.log(receiver);
                // set中劫持数据后就能进行设置
                target[key] = value

            }
        })
        // 通过代理得到proxy代理的属性值 ，get必须要有返回值，否则undefined
        console.log(proxy.name);
        proxy.name = 'luobo';
        console.log(proxy);
        proxy.name = 'hanweicheng';
        console.log(proxy);
        console.log(obj);
    </script>
</body>
</html>